﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ZLibNet;

namespace WpfWordsLearner
{
	public sealed class CompressionModule
	{
		public void Compress(string folder, string outputFile)
		{
			if (string.IsNullOrEmpty(folder))
				throw new ArgumentNullException("folder");

			if (string.IsNullOrEmpty(outputFile))
				throw new ArgumentException("outputFile");

			Zipper zip = new Zipper();
			zip.ZipFile = outputFile;

			zip.ItemList.Add(System.IO.Path.Combine(folder, "*.xml"));
			zip.ExcludeFollowing.Add("*.backup");
			zip.PathInZip = enPathInZip.Relative;
			zip.Recurse = true;
			zip.UTF8Encoding = true;
			zip.Zip();
		}

		public void Unompress(string File, string toFolder)
		{
			if (string.IsNullOrEmpty(File))
				throw new ArgumentNullException("File");

			if (string.IsNullOrEmpty(toFolder))
				throw new ArgumentException("toFolder");

			UnZipper unzip = new UnZipper();
			unzip.Destination = toFolder;
			unzip.IfFileExist = enIfFileExist.Exception;
			unzip.ItemList.Add("*.*");
			unzip.Recurse = true;
			unzip.ZipFile = File;
			unzip.UnZip();
		}
	}
}
